<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/assets/dist/css/bootstrap.min.css">
    <style>
        p:not(:empty){
            padding: 15px;
        }
        .container{
            padding-top: 100px;
        }
        .bg-danger{
            background-color: pink;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="form-group">
            <label>邮箱地址</label>
            <input type="email" class="form-control" placeholder="请输入邮箱地址" id="email">
        </div>
        <p id="info"></p>
    </div>
    <script>
        var emailinp = document.getElementById('email');
        var info = document.getElementById('info');
        emailinp.onblur = function(){
            var email = this.value;
            var reg = /^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*\.[a-z]{2,}$/;
            if(!reg.test(email)){
                info.innerHTML = '请输入符合规则的邮箱地址';
                info.className = 'bg-danger';
                return;
            }
        }
    </script>
</body>
</html>